package com.weixin.pay.utils;

import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

/**
 * 
 * @author 
 * @date 2015-1-5下午4:02:48
 * 
 * 动态native支付
 */
public class TestWinxin {
	
    public static void main(String[] args) throws Exception {
    	SortedMap<Object,Object> parameters = new TreeMap<Object,Object>();
         parameters.put("appid", ConfigUtil.APPID);                    
         parameters.put("mch_id", ConfigUtil.MCH_ID);           
         parameters.put("nonce_str", PayCommonUtil.createNoncestr());
         parameters.put("body", "测试NATIVE支付");
         parameters.put("out_trade_no", "20140107001");
         parameters.put("total_fee", "1");                             
         parameters.put("spbill_create_ip","127.0.0.1");
         parameters.put("notify_url", ConfigUtil.NOTIFY_URL);//支付成功后回调的action，与JSAPI相同
         parameters.put("trade_type", "NATIVE");
         parameters.put("product_id", "No.20140105003");//商品号要唯一
         String sign = PayCommonUtil.createSign("UTF-8", parameters);
         parameters.put("sign", sign);
         String requestXML = PayCommonUtil.getRequestXml(parameters);
         String result =CommonUtil.httpsRequest(ConfigUtil.UNIFIED_ORDER_URL, "POST", requestXML);
         System.out.println(result);
         Map<String, String> map = XMLUtil.doXMLParse(result);
         String returnCode = map.get("return_code");
         String resultCode = map.get("result_code");
         if(returnCode.equalsIgnoreCase("SUCCESS")&&resultCode.equalsIgnoreCase("SUCCESS")){
            String codeUrl = map.get("code_url");
            //TODO 拿到codeUrl，写代码生成二维码
            System.out.println("codeUrl="+codeUrl);
         }
    }
}